package com.atguigu.lease.admin.controller.lease;

import com.atguigu.lease.admin.service.LeaseAgreementService;
import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.model.bean.LeaseAgreement;
import com.atguigu.lease.model.vo.lease.AgreementItemVo;
import com.atguigu.lease.model.vo.lease.AgreementQueryVo;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author LOGIN
 * @title AgreementController
 * @create 2025/6/27 14:29
 * @description
 */
@Tag(name="租约管理模块")
@RestController
@RequestMapping("/admin/agreement")
public class AgreementController {
    @Autowired
    private LeaseAgreementService leaseAgreementService;
//    /admin/agreement/updateStatusById`
    @Operation(summary = "5、根据id修改租约状态")
    @PostMapping("/updateStatusById")
    public Result updateStatusById(@RequestParam Long id,
                                   @RequestParam String status){
        return Result.ok(leaseAgreementService.update(Wrappers.lambdaUpdate(LeaseAgreement.class)
                .eq(LeaseAgreement::getId,id)
                .set(LeaseAgreement::getStatus,status)));
    }

//    /admin/agreement/removeById?id=7
    @Operation(summary = "4、根据id删除租约信息")
    @DeleteMapping("removeById")
    public Result removeById(@RequestParam Long id){
        return Result.ok(leaseAgreementService.removeById(id));
    }

//    /admin/agreement?id=7
    @Operation(summary = "3、根据id查询租约信息")
    @GetMapping
    public Result<AgreementItemVo> getAgreementItemVo(@RequestParam Long id) {
        return Result.ok(leaseAgreementService.getAgreementItemVo(id));
    }

//    /admin/agreement/saveOrUpdate
    @Operation(summary = "2、保存或修改租约信息")
    @PostMapping("/saveOrUpdate")
    public Result saveOrUpdate(@RequestBody LeaseAgreement leaseAgreement  ) {
        leaseAgreementService.saveOrUpdate(leaseAgreement);
        return Result.ok();
    }
//    /admin/agreement/page?current=1&size=10
    @Operation(summary = "1、条件分页查询")
    @GetMapping("/page")
    public Result<Page<AgreementItemVo>> page(@RequestParam Long current,
                                              @RequestParam Long size,
                                              AgreementQueryVo agreementQueryVo){
        Page<AgreementItemVo> page = leaseAgreementService.PageItem(current,size,agreementQueryVo);
        return Result.ok(page);
    }
}
